package com.zbcz.crm.fragment.marketmanager

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.zbcz.crm.MarketManagerActivity
import com.zbcz.crm.adapter.ProjectEstablishmentAdapter
import com.zbcz.crm.databinding.FragmentCommonListBinding
import com.zbcz.crm.viewmodel.ProjectEstablishmentViewModel

class ProjectEstablishmentFragment : Fragment() {
    private lateinit var binding: FragmentCommonListBinding

    private val mViewModel: ProjectEstablishmentViewModel by viewModels()

    companion object {
        fun createProjectEstablishFragment(id: String): ProjectEstablishmentFragment {
            return ProjectEstablishmentFragment().apply {
                val args = Bundle()
                args.putString(MarketManagerActivity.PROJECT_ID, id)
                arguments = args
            }
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentCommonListBinding.inflate(inflater, container, false)
        init()
        return binding.root
    }

    fun init() {
        val id = arguments?.getString(MarketManagerActivity.PROJECT_ID)
        mViewModel.queryProjectEstablishment(id)
        mViewModel.mResult.observe(requireActivity()) {
            binding.mList.adapter = it?.let { it1 -> ProjectEstablishmentAdapter(it1) }
        }
    }
}